package com.huawei.hms.framework.network.grs.b.a;

import android.text.TextUtils;
import com.huawei.hms.framework.common.Logger;
import com.huawei.hms.framework.network.grs.b.b.c;
import com.huawei.hms.framework.network.grs.c.d;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;

public class a {
    private static final String a = a.class.getSimpleName();
    private static c b;

    public static synchronized c a() {
        c cVar;
        List list = null;
        synchronized (a.class) {
            if (b != null) {
                cVar = b;
            } else {
                Object a = d.a("grs_sdk_server_config.json");
                if (!TextUtils.isEmpty(a)) {
                    try {
                        JSONObject jSONObject = new JSONObject(a).getJSONObject("grs_server");
                        JSONArray jSONArray = jSONObject.getJSONArray("grs_base_url");
                        if (jSONArray != null && jSONArray.length() > 0) {
                            list = new ArrayList();
                            for (int i = 0; i < jSONArray.length(); i++) {
                                list.add(jSONArray.get(i).toString());
                            }
                        }
                        b = new c();
                        b.a(list);
                        b.a(jSONObject.getString("grs_query_endpoint"));
                        b.a(jSONObject.getInt("grs_query_timeout"));
                    } catch (Throwable e) {
                        Logger.w(a, "getGrsServerBean catch JSONException", e);
                    }
                    cVar = b;
                }
            }
        }
        return cVar;
    }
}
